package com.omkarpatil.learningjpa2.mapping.onetoone.jointable;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinTable;
import javax.persistence.OneToOne;
import javax.persistence.Table;
import javax.persistence.JoinColumn;

@Entity(name="OtoJoinTableEmployee") 
@Table(name = "oto_join_employee")
public class Employee {
	
	private int id;
	private String name;
	private Desk desk;
	
	public Employee() {}

	public Employee(String name) {
		this.name = name;
	}

	@Id @GeneratedValue
	public int getId() {
		return id;
	}
	
	private void setId(int id) {
		this.id = id;
	}
	
	@Column(nullable = false, length = 30)
	public String getName() {
		return name;
	}
	
	public void setName(String name) {
		this.name = name;
	}

	@OneToOne
	@JoinTable(
		name="oto_join_emp_desk",
		joinColumns = @JoinColumn(name = "emp_id"),
		inverseJoinColumns = @JoinColumn(name = "desk_id", unique = true)
	)	
	public Desk getDesk() {
		return desk;
	}

	public void setDesk(Desk desk) {
		this.desk = desk;
	}
}
